package com.deng.performance.first.view
{
	import com.deng.common.vo.EmployeeVo;
	import com.deng.event.ReturnEvent;
	
	import flash.events.MouseEvent;
	
	import mx.controls.Alert;
	import mx.controls.CheckBox;
	import mx.events.CloseEvent;
	import mx.events.FlexEvent;
	import mx.resources.ResourceManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;

	public class AdminValidCB extends CheckBox
	{
		private var selVo:EmployeeVo;
		public function AdminValidCB()
		{
			this.addEventListener(FlexEvent.CREATION_COMPLETE,showHandler);
			this.addEventListener(MouseEvent.MOUSE_UP,upEvt);
			this.addEventListener(FlexEvent.SHOW,showHandler);
			super();
		}
		private function upEvt(evt:MouseEvent):void{
			Alert.show("一旦审核将无法修改，是否审核该条数据？", 
				ResourceManager.getInstance().getString("lang", "valid_data"), 
				Alert.YES | Alert.NO, null, onAlertClose);
		}
		private function onAlertClose(event:CloseEvent):void{
			if(event.detail == Alert.YES){
				var ro:RemoteObject = new RemoteObject();
				ro.destination = "AdminBonusImpl";			
				ro.addEventListener(FaultEvent.FAULT,flt);
				ro.addEventListener(ResultEvent.RESULT,updateRst);
				ro.validData(selVo);
			}else{
				this.selected = false;
			}
		}
		
		private function updateRst(evt:ResultEvent):void{
			new ReturnEvent(ReturnEvent.searchAdminEmpByUpdate).dispatch();
			Alert.show(ResourceManager.getInstance().getString("lang", "update_success"));
		}
		private function flt(evt:FaultEvent):void{
			Alert.show(evt.fault.getStackTrace());
		}
		private function showHandler(evt:FlexEvent):void{
			selVo = this.data as EmployeeVo;
			if(selVo.valid == 1){
				this.selected = true;
				this.enabled = false;
				this.mouseEnabled = false;
			}else{
				this.selected = false;
				this.mouseEnabled = true;
				this.enabled = true;
			}				
		}
	}
}